﻿
using Glorysoft.EAP.Core.Enums;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace Glorysoft.EAP.EAPClient.Common
{
    [ValueConversion(typeof(string), typeof(Color))]
    public class WaferState2Color : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Color _color;
            if (value == null)
                _color = Colors.Black;
            else
            {
                var state = value.ToString();
                if (state== "WaferNothing")
                {
                    _color = Colors.Black;
                }
           else if (state == "WaferIn")
                {
                    _color = Colors.Black;
                }
                else if (state == "WaferEnd")
                {
                    _color = Colors.Green;
                }
                else if (state== "Waiting")
                {
                    _color = Colors.Black;
                }
                else if (state == "Testing")
                {
                    _color = Colors.Green;
                }
                else
                {
                    _color = Colors.Gray;
                }  
                //WaferState _WaferState = (WaferState)value;
                //if (Consts.WaferStateColorMap.ContainsKey(_WaferState))
                //    _color = Consts.WaferStateColorMap[_WaferState];
                //else
                //    _color = Colors.Black;

            }
            return new SolidColorBrush(_color);
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(bool), typeof(Color))]
    public class Connect2Color : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var boolvalue = (bool)value;
            if (boolvalue == true)
                return new SolidColorBrush(Colors.Green);
            else
                return new SolidColorBrush(Colors.Red);

        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    [ValueConversion(typeof(ProcessState), typeof(string))]
    public class ProcessState2Color : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var state = (ProcessState)Enum.Parse(typeof(ProcessState), value.ToString());
            if (Consts.LotStateColorMap.ContainsKey(state))
                return Consts.LotStateColorMap[state].ToString();
            return "#cccccc";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        #endregion
    }
    [ValueConversion(typeof(int), typeof(Visibility))]
    public class CarrierMapConverter : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string carrierqty = (string)value;
            string row = (string)parameter;
            if (System.Convert.ToInt32(carrierqty)> System.Convert.ToInt32(row))
                return Visibility.Visible;
            return Visibility.Visible;
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        #endregion
    }

    [ValueConversion(typeof(string), typeof(string))]
    public class BackGround2Color1 : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
                return "white";
            return "Transparent";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class BackGround2Color2 : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
                return "#c6e0f9";
            return "Transparent";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class Conn2Visibility2 : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.ToString() == "OFFLINE")
                return "Hidden";
            return "Visible";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class ScanColor2 : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
                return "Green";
            return "#FCFCFC";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(int))]
    public class PortNumber2Height : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //if (value != null && value.ToString() == "1")
            //    return 700;
            //if (value != null && value.ToString() == "2")
            //    return 500;
            //return 400;

            double heights = SystemParameters.WorkArea.Size.Height - 220;
            return heights;
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(int))]
    public class PortNumberWidth : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double widths = 600;//(SystemParameters.WorkArea.Size.Width-60) / 4;
            return widths;
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    [ValueConversion(typeof(string), typeof(int))]
    public class PortNumber2Width : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double widths = 300;//(SystemParameters.WorkArea.Size.Width-100)/4;
            return widths;
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class Button2Color : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()) && value.ToString() == "ATT-DZ01")
                return "Green";
            return "red";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class GREENColor : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()) && value.ToString() == Consts.GREEN)
                return "#000000";
            return "#33CC33";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class REDColor : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()) && value.ToString() == Consts.RED)
                return "#000000";
            return "RED";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class YELLOWColor : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()) && value.ToString() == Consts.YELLOW)
                return "#000000";
            return "YELLOW";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class ErrorColor : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
            {
                if (value.ToString() == Consts.RED)
                    return "RED";
                else if (value.ToString() == Consts.GREEN)
                    return "GREEN";
                else if (value.ToString() == Consts.RUNNING)
                    return "SKYBLUE";
            }
            return "Transparent";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class Error2Color : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
            {
                if (value.ToString() == Consts.RED || value.ToString() == Consts.GREEN || value.ToString() == Consts.RUNNING)
                    return "#999";
            }
            return "Transparent";
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(string))]
    public class EqpMsgColor : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
                return "&#xf10c; " + value.ToString();
            return "&#xf10c; "+ Consts.GetTranslation("Msg_RealtimeInfo");
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(Visibility), typeof(Visibility))]
    public class SkipColor : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && (Visibility)value == Visibility.Visible)
                return Visibility.Visible;
            return Visibility.Collapsed;
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    [ValueConversion(typeof(string), typeof(Visibility))]
    public class FIconShow : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()) && value.ToString().ToLower() != "null")
                return Visibility.Visible;
            return Visibility.Collapsed;
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    [ValueConversion(typeof(string), typeof(string))]
    public class LanguageConverter : IValueConverter
    {
        public object Convert(object values, Type targetType, object parameter, CultureInfo culture)
        {
            string language = (string)values;
            string paraname = (string)parameter;
            if (language == "EN")
            {
                return Consts.Translator[paraname].Split(':')[1];
            }
            else //language=="CN"
            {
                return Consts.Translator[paraname].Split(':')[0];
            }
        }
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
